package jp.kiroru_inc.rs_sample;

import android.content.Context;
import android.renderscript.RSTextureView;
import android.renderscript.RenderScriptGL;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * SampleScript を表示するための UI です。<br/>
 * <br/>
 * <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">
 * <img alt="クリエイティブ・コモンズ・ライセンス" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png" />
 * </a><br/>
 * <span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">RSSample</span> by 
 * <a xmlns:cc="http://creativecommons.org/ns#" href="http://sakplus.jp/" property="cc:attributionName" rel="cc:attributionURL">
 * Selphy, Kiroru Inc.
 * </a>
 *  is licensed under a 
 * <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">
 * Creative Commons 表示 - 非営利 - 継承 3.0 非移植 License
 * </a>.
 * @author selphy
 */
public class MainTextureView extends RSTextureView {
	private SampleScript script;
	private RenderScriptGL rs;

	public MainTextureView(Context context, AttributeSet attrs) {
		super(context, attrs);
		if (rs == null) {
			RenderScriptGL.SurfaceConfig config = new RenderScriptGL.SurfaceConfig();
			rs = createRenderScriptGL(config);
		}
		if (script == null)
			script = new SampleScript(rs, getResources());
	}

	@Override
	protected void onDetachedFromWindow() {
		script = null;
		if (rs != null) {
			rs = null;
			destroyRenderScriptGL();
		}
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		super.onTouchEvent(event);
		script.touchEvent(event.getAction(), event.getX(), event.getY());
		return true;
	}

}
